package cn.tyoui.ssm.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.tyoui.ssm.po.ItemsCustom;
import cn.tyoui.ssm.po.User;
import cn.tyoui.ssm.po.UserCustom;
import cn.tyoui.ssm.service.interFace.ItemsService;

@Controller
public class ListController {

	@Autowired
	private ItemsService itemsService;

	@RequestMapping("/list1")
	public void list1(Integer[] ids) {
		for (Integer integer : ids) {
			System.out.println(integer);
		}
	}

	@RequestMapping("/list")
	public void list(UserCustom custom) {
		for (User user : custom.getUsers()) {
			System.out.println(user.toString());
		}
	}

	@RequestMapping("/view/{id}")
	public @ResponseBody
	ItemsCustom edit(@PathVariable("id") Integer id) throws Exception {
		ItemsCustom itemsCustom = itemsService.findItemsById(id);
		return itemsCustom;
	}

	@RequestMapping("/login")
	public String login(HttpSession session, String username, String password)
			throws Exception {
		session.setAttribute("username", username);
		return "redirect:/queryItems.action";
	}

	@RequestMapping("/logout")
	public String logout(HttpSession session) throws Exception {
		session.invalidate();
		return "redirect:/queryItems.action";
	}

}
